#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Name : __init__.py
# Author: ls_seraph@126.com
# Time  : 2021/3/6 22:46

import xlrd


# excel表数据读取
class ElementDateUtils():
    def __init__(self, excel_path):
        self.excel_path = excel_path
        self.workbook = xlrd.open_workbook(self.excel_path)

    def get_element_info(self, sheet_title):
        """
        读取表中数据
        :param sheet_title: 页面名，对应表中的页面名称
        :return element_infos:序列[{element_name:"",locator_type:""}]
        """
        worksheet = self.workbook.sheet_by_name(sheet_title)
        row_cont = worksheet.nrows
        element_infos = {}
        for i in range(1, row_cont):
            element_info = {
                'element_name': worksheet.cell_value(i, 1),
                'locator_type': worksheet.cell_value(i, 2),
                'locator_value': worksheet.cell_value(i, 3),
                'timeout': worksheet.cell_value(i, 4)
            }
            element_infos[worksheet.cell_value(i, 0)] = element_info
        return element_infos
